<?php
class mcz_TuneIndex extends mcz_Object
{
    protected $fields = array(
        'id' => array('cast' => 'integer'),
        'key' => array('cast' => 'string',
                       'notblank' => true,),
        'field' => array('cast' => 'string',
                         'notblank' => true),
        'tune_id' => array('cast' => 'integer',
                           'notblank' => true),
        'sound' => array('cast' => 'string')
    );

    public function preSave()
    {
        $this->sound = metaphone($this->key);
    }

    public static function deleteFromTuneId($id)
    {
        $res = self::dbh()->exec('delete from ' . get_class()
                                 . ' where tune_id = ' . (int)$id);
    }
}